# Python sorted函数及用法
## 对列表进行排序
a = [5, 4, 3, 2, 1]
print("sorted(a) =", sorted(a))
print()

## 对元组进行排序
a = (5, 4, 3, 2, 1)
print("sorted(a) =", sorted(a))
print()

## 字典默认按照key进行排序
a = {4:1, 5:2, 3:3, 2:6, 1:8}
print("sorted(a.items()) =", sorted(a.items()))

## 对集合进行排序
a = {1, 5, 3, 2, 4}
print("sorted(a) =", sorted(a))

## 对字符串进行排序
a = "51423"
print("sorted(a) =", sorted(a))
print()

## 对列表进行排序
a = [5, 4, 3, 2, 1]
print("sorted(a) =", sorted(a))
## 再次输出原来的列表 a
print("a =", a)
print()

## 对列表进行排序
a = [5, 3, 4, 2, 1]
print("sorted(a, reverse = True) =", sorted(a, reverse = True))
print()

chars = ["http://c.biancheng.net", "http://c.biancheng.net/python/",
         "http://c.bianchent.net/shell/", "http://c.biancheng.net/java/",
         "http://c.biancheng.net/golang/"]
## 默认排序
print("sorted(chars) =", chars)
## 自定义按照字符串长度排序
print("sorted(chars, key = lambda x:len(x)) =", sorted(chars, key = lambda x:len(x)))
